package security.IntrusionDetection.Base;

import java.io.File;

import security.Authentication.Base.AuthenticationHandler;
import security.Authentication.Base.AuthenticationRequest;
import security.Authentication.Base.UnknownUser;
import security.Authentication.Base.User;
import security.Authentication.UserPass.UserPassRequest;

/**
 * Abstract class which provides the backbone of the intrusion detection system.
 * All other security measures must inherit from this class.
 * @author Danut
 *
 */
public abstract class IntrusionDetection extends AuthenticationHandler{
	
	protected File log;
	/**
	 * This method will handle the next request in the chain.
	 * @param request A request for authentication in the system
	 */
	@Override
	public User handleRequest(AuthenticationRequest request){
		if(request instanceof UserPassRequest)
			//Detecting a possible intrusion
			if(isPossibleIntrusion(request))
				return new UnknownUser("An intrusion was detected", true);

		return passRequestToNext(request);
	}
	
	/**
	 * This method will try and detect if the IP is a previously logged in IP.
	 * We will try to find the IP in the log file.
	 * @param ip IP which tries to authenticate with the system
	 * @return True if the IP is not part of the previously used IP's
	 */
	public abstract boolean isPossibleIntrusion(AuthenticationRequest auth);
	public void setLogFile(File f){log=f;}
}
